package com.molin.StreamTest;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

public class Demo3 {
    public static void main(String[] args) {
        ArrayList<String> nameList = new ArrayList<>(List.of("张三丰", "张无忌", "谢敏", "张良", "王二麻子", "张隆基"));
//        setp1(nameList);
//        setp2(nameList);
        setp3(nameList);

    }

    public static void setp3(ArrayList<String> nameList) {
        //setp3 lambda的简化
        nameList.stream().filter(s->s.startsWith("张")).forEach(s-> System.out.println(s));
    }

    public static void setp2(ArrayList<String> nameList) {
        //setp2
        nameList.stream().filter(
                (String s)->{
                  return    s.startsWith("张");
                }
        ).forEach(s-> System.out.println(s));
    }

    public static void setp1(ArrayList<String> nameList) {
        //setp1 匿名类实现Predicate<T>接口
        // filter过滤

        nameList.stream().filter(
                new Predicate<String>() {
                    @Override
                    //true 保留数据，flase 丢弃数据
                    public boolean test(String s) {
                        return s.startsWith("张");
                    }
                }
        )
                .forEach(s -> System.out.println(s));
    }

}
